<template>
	<div class="app-container">
		<div class="head-container">
			<div v-if="crud.props.searchToggle">
				<el-input v-model="query.companyName" clearable size="small" placeholder="全表模糊搜索" style="width: 200px;"
					class="filter-item" @keyup.enter.native="crud.toQuery" />
				<rrOperation />
			</div>
			<crudOperation :permission="permission" />
		</div>

		<!-- 表单 -->
		<el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU"
			:visible.sync="crud.status.cu > 0" :title="crud.status.title" width="680px">
			<el-form ref="form" :model="form" label-width="120px">
				<el-form-item label="公司名称">
					<el-input v-model="form.companyName" />
				</el-form-item>
				<el-form-item label="联系热线">
					<el-input v-model="form.phoneNumber" />
				</el-form-item>
				<el-form-item label="公司所在城市">
					<el-select v-model="form.companyCity" placeholder="请选择公司所在的城市">
						<el-option v-for="(item,index) in cityList" :key="index" :label="item.value"
							:value="item.value" />
					</el-select>
				</el-form-item>
				<el-form-item label="公司地址">
					<el-input v-model="form.address" />
				</el-form-item>
				<el-form-item label="工作时间">
					<el-input v-model="form.workingHours" />
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="text" @click="crud.cancelCU">取消</el-button>
				<el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
			</div>
		</el-dialog>

		<!--表格渲染-->
		<el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;"
			@selection-change="crud.selectionChangeHandler">
			<el-table-column type="selection" width="55" />
			<el-table-column prop="companyName" align="center" label="公司名称" />
			<el-table-column prop="phoneNumber" align="center" label="联系热线" width="200px" />
			<el-table-column prop="companyCity" align="center" label="公司所在城市" />
			<el-table-column prop="address" align="center" label="公司地址" width="200px" />
			<el-table-column prop="workingHours" align="center" label="工作时间" width="300px" />
			<el-table-column v-if="checkPer(['admin','menu:edit','menu:del'])" align="center" label="操作" width="150px"
				fixed="right">
				<template slot-scope="scope">
					<udOperation :data="scope.row" :permission="permission" msg="确定删除吗，此操作不能撤销！" />
				</template>
			</el-table-column>
		</el-table>
		<!--分页组件-->
		<pagination />
	</div>
</template>

<script>
	import crudContactUs from '@/api/finace_taxation/contact_us.js'
	import CRUD, {
		presenter,
		header,
		form,
		crud
	} from '@crud/crud'
	import rrOperation from '@crud/RR.operation'
	import crudOperation from '@crud/CRUD.operation'
	import pagination from '@crud/Pagination'
	import udOperation from '@crud/UD.operation'

	// crud交由presenter持有
	const defaultForm = {
		companyName: null,
		companyCity: null,
		workingHours: null,
		address: null,
		phoneNumber: null,
		permission: null
	}

	export default {
		name: 'ContactUs',
		components: {
			pagination,
			crudOperation,
			rrOperation,
			udOperation
		},
		cruds() {
			return CRUD({
				url: 'api/ft/ftContactUs',
				title: '联系我们',
				crudMethod: {
					...crudContactUs
				}
			})
		},
		mixins: [presenter(), header(), form(defaultForm), crud()],
		data() {
			return {
				delLoading: false,
				permission: {
					add: ['admin', 'ftContactUs:add'],
					edit: ['admin', 'ftContactUs:edit'],
					del: ['admin', 'ftContactUs:del']
				},
				cityList: []
			}
		},
		created() {
			this.crud.optShow = {
				add: true,
				reset: true
			}
			this.dictDetail()
		},
		methods: {
			dictDetail() {
				const params = {
					dictName: 'company_city'
				}
				setTimeout(() => {
					crudContactUs.dictDetail(params).then(res => {
						this.cityList = res.company_city
					})
				}, 100)
			}
		}
	}
</script>
